package com.crm.redis.service.common.impl;

import com.crm.model.entity.cluePoolManager.CluePoolPrivate;
import com.crm.model.entity.common.Dictionary;
import com.crm.redis.RedisPrefix;
import com.crm.redis.mapper.ValueRMapper;
import com.crm.redis.service.cluePoolManager.CluePoolPrivateRedisService;
import com.crm.redis.service.common.DictionaryRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @author luojie
 * @date 2021/5/13 16:40
 */
@Service
public class DictionaryRedisServiceImpl implements DictionaryRedisService {

    @Autowired
    private StringRedisTemplate redisTemplate;

    /**
     * 根据id获取key
     * @param typeCode/dictCode
     * @return
     */
    private String getKey(String typeCode, String dictName){
        String key = RedisPrefix.DICTIONARY + typeCode + dictName;
        return key;
    }

    @Override
    public Dictionary getByCode(String typeCode, String dictName) {
        String key = getKey(typeCode, dictName);
        Dictionary dictionary = ValueRMapper.getRedisObject(redisTemplate, key, Dictionary.class);
        return dictionary;
    }

    @Override
    public Boolean setByCode(Dictionary dictionary) {
        String typeCode = dictionary.getTypeCode();
        String dictName = dictionary.getDictName();
        String key = getKey(typeCode, dictName);
        return ValueRMapper.setRedisObject(redisTemplate,key,dictionary);
    }

    @Override
    public Boolean deleteClueById(String typeCode, String dictName) {
        return null;
    }

}
